package com.shuwen.gcdj.common.error;

import com.shuwen.gcdj.common.api.CommonResult;
import com.shuwen.gcdj.common.api.IErrorCode;
import com.shuwen.gcdj.common.enums.ErrorCode;

/**
 * 错误包装
 */
public class ErrorReport<T> extends CommonResult<T> {

    /**
     * 检验是否错误
     *
     * @param wrap ErrorCode
     * @return boolean
     */
    public static boolean hasError(IErrorCode wrap) {
        return wrap.getCode() != ErrorCode.SUCCESS.getCode();
    }

    public static <T> CommonResult<T> fail(IErrorCode wrap) {
        return CommonResult.failed(wrap, wrap.getMessage());
    }

    public static <T> CommonResult<T> success(T data) {
        return CommonResult.success(data);
    }
}
